import sys
import time
import requests
import json
with open("E:/python/tianlongbabu/2022-4-16练习/weblog.txt",'r') as fp:
    with open("result.txt",'w') as fp1:
        for i in fp:
            lst1 = i.split()
            #将文件中的内容读取出来，以空格分割存放入lst1
            lst1[3] = lst1[3][1:]
            #利用切片的方法去掉时间前面的【去掉
            lst1[3] = time.strptime(lst1[3],"%d/%b/%Y:%H:%M:%S")
            #将文本格式的时间利用函数变成元组存入lst1【3】
            lst1[3] = time.mktime(lst1[3])
            lst1[3] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(lst1[3]))
            #按照顺序，使用函数，将元组变成自己想要的字符格式
            # print(lst1[0],lst1[3],lst1[9])
            response = requests.get(" https://ip.taobao.com/outGetIpInfo?accessKey=alibaba-inc&ip=" + lst1[0])
            #使用requests去调用接口，得到请求包
            # print(response.text)
            re_package = response.json()
            # print(re_package)
            isp1 = re_package["data"].get('isp')
            region1 = re_package["data"].get('region')
            str2 = (f"{lst1[3]},{isp1},{region1},{lst1[9]}\n")
            fp1.write(str2)
            # print(str2)
